package spritebehavior;

import java.awt.Point;
import java.awt.event.KeyEvent;
import sprite.Sprite;
import utility.Bounce;
import utility.MoveDownward;
import utility.MoveLeftward;
import utility.MoveRightward;
import utility.MoveUpward;
import gamehandlers.GameHandler;


/**
 * This extended interface is for Player strategies. This allows Player
 * strategies to define
 * user controlled actions.
 * 
 * @author Seon Kang
 * @author Yaqi Zhang
 */
public class PlayerBehavior implements Behavior {
    private static int PLAYER_SPEED = 10;
    private Sprite mySprite;
    private GameHandler myGameHandler;

    /**
     * 
     * @param sp sprite
     * @param gh GameHandler
     */
    public PlayerBehavior (Sprite sp, GameHandler gh) {
        mySprite = sp;
        myGameHandler = gh;
    }

    @Override
    public void update () {
        move();
        wallCollision();
    }

    /**
     * move player
     */
    public void move () {
        // this will be change into a mapping between key and reaction
        int keyPressed = myGameHandler.getUserKeyInput();
        if (keyPressed == KeyEvent.VK_UP) {
            MoveUpward.apply(mySprite, PLAYER_SPEED);
        }
        if (keyPressed == KeyEvent.VK_DOWN) {
            MoveDownward.apply(mySprite, PLAYER_SPEED);
        }
        if (keyPressed == KeyEvent.VK_LEFT) {
            MoveLeftward.apply(mySprite, PLAYER_SPEED);
        }
        if (keyPressed == KeyEvent.VK_RIGHT) {
            MoveRightward.apply(mySprite, PLAYER_SPEED);
        }
    }

    private void wallCollision () {
        if (myGameHandler.isHitLeftRightWall(mySprite)) {
            Point currentLoc = mySprite.getCenter();
            // set the center back
        }
        if (myGameHandler.isHitTopBottomWall(mySprite)) {
            // set the center back
        }
    }

    @Override
    public void setGameHandler (GameHandler gh) {
        myGameHandler = gh;
    }
}
